package com.xiyoukt.springboot.controller;

import com.xiyoukt.springboot.Result;
import com.xiyoukt.springboot.entity.User;
import com.xiyoukt.springboot.util.ResultUtil;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Description: springboot
 * ********************************************************
 * *                                                      *
 * *                     xiyoukt.com                      *
 * *          西游课堂 - Java程序猿的在线学习课堂          *
 * *                                                      *
 * ********************************************************
 * Created by xiyoukt on 2018/9/24 0:33
 */
@Api(value = "用户API", description = "用户相关操作的API2")
@RestController
@Slf4j
public class UserController {

    @Value("${testValue}")
    private String testValue;

    @ApiOperation(value = "添加用户", notes = "这个接口是用来添加用户的")
//    @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "姓名", required = true),
//            @ApiImplicitParam(name = "gender", value = "性别", required = true),
//            @ApiImplicitParam(name = "age", value = "年龄", required = true)})
    @ApiResponses({@ApiResponse(code = 500, message = "发生未知异常"),
    @ApiResponse(code = 401, message = "参数不正确")})
    @PostMapping("addUser")
    public Result<Boolean> addUser(User user){
        ResultUtil<Boolean> resultUtil = new ResultUtil<>();
        // 进行相应的添加操作
        return resultUtil.success(Boolean.TRUE);
    }

    @ApiOperation(value = "查询用户2", notes = "用来查询用户")
    @ApiResponses({@ApiResponse(code = 500, message = "发生未知异常"),
            @ApiResponse(code = 401, message = "参数不正确")})
    @ApiImplicitParam(name = "id", value = "用户id", required = true)
    @GetMapping("getUser")
//    public Result<User> getUser(@ApiParam(name = "id", value = "用户id", required = true) Integer id){
    public Result<User> getUser(Integer id){
        ResultUtil<User> resultUtil = new ResultUtil<>();
        // 进行相应的添加操作
        User user = new User("张三", 24, 0);
        log.info(testValue);
        return resultUtil.success(user);
    }

}
